package com.sankuai.inf.leaf.segment.dao;
import com.sankuai.inf.leaf.segment.model.LeafAllocEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author final
 * @description
 * @date 2019-09-11 15:16
 */
public interface LeafAllocMapper {
    @Select("SELECT biz_tag, max_id, step,description,update_time FROM leaf_alloc")
    @Results(value = {
            @Result(column = "biz_tag", property = "bizTag"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "description", property = "description"),
            @Result(column = "update_time", property = "updateTime")
    })
    List<LeafAllocEntity> getLeafAllocEntitys();

    @Select("SELECT biz_tag, max_id, step,description,update_time FROM leaf_alloc WHERE biz_tag = #{tag}")
    @Results(value = {
            @Result(column = "biz_tag", property = "bizTag"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "description", property = "description"),
            @Result(column = "update_time", property = "updateTime")
    })
    LeafAllocEntity getLeafAllocEntity(@Param("tag") String tag);

    @Update("UPDATE leaf_alloc SET description = #{description} WHERE biz_tag = #{bizTag}")
    void updateDescription(@Param("leafAllocEntity") LeafAllocEntity leafAllocEntity);

    @Insert("INSERT  INTO `leaf_alloc` (biz_tag, max_id, step,description) VALUES(#{bizTag},#{maxId},#{step},#{description})")
    int insertLeafAllocEntity(@Param("leafAllocEntity") LeafAllocEntity leafAllocEntity);
}
